import functools
import json

from flask import (
    Blueprint, flash, g, redirect, render_template, request, session, url_for,jsonify,Response,abort
)
from werkzeug.security import check_password_hash, generate_password_hash

from flaskr.db import get_db

from flask_cors import *

bp = Blueprint('medical-point', __name__, url_prefix='/')

cors=CORS(bp,supports_credentials=True)

@bp.route('/get-medical-point-list', methods=['GET'])
def login():
    if request.method == 'GET':
        if(session.get('permission') != 'User'):
            abort(403)
        db = get_db()
        appointment_id = db.execute(
            'SELECT appointment_id FROM User WHERE id = ?', (session.get('id'),)
            ).fetchone()[0]
        list = db.execute(
            'SELECT id,username,nucleic_acid,nucleic_acid_waiting,vaccine_B,vaccine_K,vaccine_waiting,phone,address,create_time FROM Medical_point',
            ).fetchall()
        medical_point_list = [];
        for record in list:
            medical_point_list.append({'id':record['id'],'username':record['username'],
            'nucleic_acid':record['nucleic_acid'],'nucleic_acid_waiting':record['nucleic_acid_waiting'],
            'vaccine_B':record['vaccine_B'],'vaccine_K':record['vaccine_K'],'vaccine_waiting':record['vaccine_waiting'],
            'phone':record['phone'],'address':record['address'], 'create_time':record['create_time']})
        return jsonify({'medical_point_list':medical_point_list, 'appointment_id':appointment_id})
    abort(405)  #method not allowed
